package com.linwen.excise.leetcode;

/**
 * @ClassName _896单调数列
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/28 5:32 PM
 * @Version 1.0
 */
public class _896单调数列 {
    public static void main(String[] args) {
        _896单调数列 inst = new _896单调数列();
        int[] nums = {1,2,2,3};
        System.out.println(inst.isMonotonic(nums));
    }
    public boolean isMonotonic(int[] nums) {
        if (nums == null) {
            return false;
        }
        if (nums.length <= 2) {
            return true;
        }
        int temp = nums[0] - nums[nums.length - 1];
        if (temp < 0) {
            for (int i = 0; i < nums.length - 1; i++) {
                if (nums[i] > nums[i + 1]) {
                    return false;
                }
            }
        } else {
            for (int i = 0; i < nums.length - 1; i++) {
                if (nums[i] < nums[i + 1]) {
                    return false;
                }
            }
        }
        return true;
    }
}
